#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int t = 0;
    string s1, s2;
    cin >> t;
    while (t--)
    {
        cin >> s1 >> s2;
        vector<int> arr(26);
        for (int i = 0; i < s1.size(); ++i)
        {
            ++arr[s1[i] - 'a'];
        }
        int count = 0;
        while (1)
        {
            for (int i = 0; i < s2.size(); ++i)
            {
                if (arr[s2[i] - 'a'] == 0)
                    goto end;
                --arr[s2[i] - 'a'];
            }
            ++count;
        }
    end:
        cout << count << endl;
    }
    return 0;
}